#pragma once

#include "CeBrainCommon.h"
#include "Nervus.h"

class CTrainingCase
{
public:
	CTrainingCase(void);
	CTrainingCase( EOBJTYPE tEnvRoundMe[ ALL_DIRECTION_COUNT ] );
	~CTrainingCase(void);

	int GetSignalForNervus( int nNervusIndex );
	RESULT_JUDGMENT CompareNervusOutputSignal( void );

	void InitOutSignal( void )
	{
		for( int i=0; i<OUTPUT_SIGNAL_COUNT; i++ )
			m_nOutputSignal[i] = 0;
	};

	void TransmitSignal( void )
	{
		for( int j=0; j<INPUT_SIGNAL_COUNT; j++ )
		{
			m_pinInput[j].SetSignal( GetSignalForNervus( j ) );
			//TRACE( "-->%d:%d", j, m_pinInput[j].GetSignal());
			m_pinInput[j].TransmitSignal();
		}
	};

	void GetOutputSignal( void )
	{
		for( int k=0; k<OUTPUT_SIGNAL_COUNT; k++ )
		{
			int nSignal = m_pinOutput[k].GetSignal();
			if( nSignal > 0 )
				m_nOutputSignal[k] += nSignal;
			else if( nSignal < 0 )
				m_nOutputSignal[k] += nSignal;
			//if( m_nOutputSignal[k] )
			//	TRACE( "Out-->[%d: %d]\n", k, m_nOutputSignal[k]);
		}
	};

	void ConnectInputOutput( CNervusNet *pNervusNet )
	{
		for( int i=0; i<OUTPUT_SIGNAL_COUNT; i++ )
			pNervusNet->GetNervus( NERVUS_NET_DEPTH-1, i )->Connect( 0, &m_pinOutput[i] );

		for( int j=0; j<INPUT_SIGNAL_COUNT; j++ )
			m_pinInput[j].Connect( pNervusNet->GetNervus( 0, j )->FindEmptyInputAntennna() );
	}

private:
	int m_nInputSignalSequence[ INPUT_SIGNAL_COUNT ][ SIGNAL_PERIOD ];
	EOBJTYPE m_tEnvRoundMe[ ALL_DIRECTION_COUNT ];
	int m_nCurrentSignal[INPUT_SIGNAL_COUNT];
	CNervusAntenna m_pinInput[ INPUT_SIGNAL_COUNT ];
	CNervusAntenna m_pinOutput[ OUTPUT_SIGNAL_COUNT ];
	int m_nOutputSignal[ OUTPUT_SIGNAL_COUNT ];
};

